<?php
class lappembeliancontroller extends CI_Controller{
	function __construct(){
		parent::__construct();
		$this->load->helper('form');
		$this->load->library('form_validation');
		$this->load->model('lappembelian_model');
		$this->load->library('pagination_editable');
		if(($this->session->userdata('fullname') == '') || ($this->session->userdata('fullname') == NULL)){
			redirect('logincontroller');
		}
	}
	
	function index()
	{
		$config = array();
		$config['per_page'] = 10;
		$config['first_tag_open'] = '<li>';
		$config['first_tag_close'] = '</li>';
		$config['curr_class'] = 'active';
		$config['full_tag_open'] = '<ul id="pagination-flickr">';
		$config['full_tag_close'] = '</ul>';
		$config['num_tag_open'] = '<li>';
		$config['num_tag_close'] = '</li>';
		$config['next_link'] = 'Next &gt;&gt;';
		$config['prev_link'] = '&lt;&lt; Previous';
		$config['next_tag_open'] = '<li class="next">';
		$config['next_tag_close'] = '</li>';
		$config['prev_tag_open'] = '<li class="previous-off">';
		$config['prev_tag_close'] = '</li>';
		
		$config["uri_segment"] = 3;
		$config["base_url"] = site_url('lappembeliancontroller/index');
		$config['total_rows'] = $this->lappembelian_model->countGetList();
		
		$this->pagination_editable->initialize($config);
	
		$page = ($this->uri->segment(3)) ? $this->uri->segment(3) : 0;
		               
		if (isset($_POST['btnview'])) {
            if ((isset($_POST['tglawal']) && isset($_POST['tglakhir'])) 
			&& (!empty($_POST['tglawal']) && !empty($_POST['tglakhir'])))
			{
				$this->lappembelian_model->setTanggalAwal($_POST['tglawal']);
				$this->lappembelian_model->setTanggalAkhir($_POST['tglakhir']);
				
				$dataprofile = array(
					'page_title' => 'Laporan > Pembelian',
					'name' => $this->session->userdata('fullname'),
					'dt_faktur' => $this->lappembelian_model->getListtanggal(),
					'links' => $this->pagination_editable->create_links(),
					'tglAwal' => $_POST['tglawal'],
					'tglAkhir' => $_POST['tglakhir']
				);  
            }
			elseif (isset($_POST['nofaktur'])) 
			{				
				$this->lappembelian_model->setNoFaktur($_POST['nofaktur']);
				$dataprofile = array(
					'page_title' => 'Laporan > Pembelian',
					'name' => $this->session->userdata('fullname'),
					'dt_faktur' => $this->lappembelian_model->getLisnofaktur(),
					'links' => $this->pagination_editable->create_links(),					
					'nofak' => $_POST['nofaktur']
				); 				
            }
			else 
			{
				$dataprofile = array(
					'page_title' => 'Laporan > Pembelian',
					'name' => $this->session->userdata('fullname'),
					'dt_faktur' => $this->lappembelian_model->getListlimit($config['per_page'],$page),
					'links' => $this->pagination_editable->create_links()
				);		
			}
        } 
		else 
		{
			$dataprofile = array(
				'page_title' => 'Laporan > Pembelian',
				'name' => $this->session->userdata('fullname'),
				'dt_faktur' => $this->lappembelian_model->getListlimit($config['per_page'],$page),
				'links' => $this->pagination_editable->create_links()
			);		
		}
		$content = array(
			'content' => 'laporan/lappembelian'
		);
		$this->template->load('templates/default',$content,$dataprofile);
	}
	
	function toExcel()
	{
		if (isset($_POST['btntoxl'])) 
		{
            if ((isset($_POST['tglawal']) && isset($_POST['tglakhir'])) 
				&& (!empty($_POST['tglawal']) && !empty($_POST['tglakhir'])))
			{
				$this->lappembelian_model->setTanggalAwal($_POST['tglawal']);
				$this->lappembelian_model->setTanggalAkhir($_POST['tglakhir']);
				$dataprofile = array(
					'page_title' => 'Laporan > Pembelian',
					'name' => $this->session->userdata('fullname'),
					'dt_faktur' => $this->lappembelian_model->getListtanggal()
				);  
            }
			elseif (isset($_POST['kdfktrno'])) 
			{
				$this->lappembelian_model->setNoFaktur($_POST['kdfktrno']);
				$dataprofile = array(
					'page_title' => 'Laporan > Pembelian',
					'name' => $this->session->userdata('fullname'),
					'dt_faktur' => $this->lappembelian_model->getLisnofaktur()
				);  
            }
			else 
			{
				$dataprofile = array(
					'page_title' => 'Laporan > Pembelian',
					'name' => $this->session->userdata('fullname'),
					'dt_faktur' => $this->lappembelian_model->getList()
				);		
			}
			
        } 
		$content = array
		(
			'content' => 'laporan/excellappembelian'
		);

		$this->load->view('laporan/excellappembelian',$dataprofile);
	}
}